package com.dotstone.chipism.adapter;

import java.util.List;

import com.dotstone.chipism.R;
import com.dotstone.chipism.bean.Province;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class ProvinceAdapter extends BaseAdapter {

	private List<Province> provinces;
	private Context c;
	public ProvinceAdapter(Context c,List<Province> provinces){
		this.c = c;
		this.provinces = provinces;
	}
	
	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return provinces.size();
	}

	@Override
	public Object getItem(int p) {
		// TODO Auto-generated method stub
		return provinces.get(p);
	}

	@Override
	public long getItemId(int p) {
		// TODO Auto-generated method stub
		return p;
	}

	@Override
	public View getView(int p, View v, ViewGroup arg2) {
		// TODO Auto-generated method stub
		if(v==null){
			v= LayoutInflater.from(c).inflate(R.layout.item_addr_selection, null);
			holdView = new HoldView();
			holdView.addr = (TextView) v.findViewById(R.id.addr_tv);
			v.setTag(holdView);
		}else{
			holdView = (HoldView)v.getTag();
		}
		Province province = provinces.get(p);
		holdView.addr.setText(province.getName());
		return v;
	}
	
	HoldView holdView;
	
	class HoldView {
		private TextView addr;
	}
}
